import {
	HtmlViewActionType,
	IHtmlViewAbility,
	IHtmlViewController,
	IHtmlViewStore,
	IParam,
} from '@/core/interface';
import { fillStrData } from '@/core/utils';
import { DEViewController } from './de-view-controller';

/**
 * HTML视图控制器
 *
 * @export
 * @class HtmlViewController
 * @extends {DEViewController<HtmlViewActionType, IHtmlViewStore, IHtmlViewAbility>}
 * @implements {IHtmlViewController<IHtmlViewStore, IHtmlViewAbility>}
 */
export class HtmlViewController
	extends DEViewController<HtmlViewActionType, IHtmlViewStore, IHtmlViewAbility>
	implements IHtmlViewController<IHtmlViewStore, IHtmlViewAbility>
{
	/**
	 * 视图挂载
	 *
	 * @param {(IParam | undefined)} [opts]
	 * @return {*}  {void}
	 * @memberof HtmlViewController
	 */
	public viewMounted(opts: IParam = {}): void {
		super.viewMounted(opts);
		if (this.model.useDefaultLayout) {
			if (!this.isLoadDefault) {
				this.isLoadDefault = true;
				return;
			}
			this.initHtmlUrl();
		} else {
			this.initLayout().then(() => {
                if (!this.isLoadDefault) {
                    this.isLoadDefault = true;
                    return;
                }
				this.initHtmlUrl();
			});
		}
	}

	/**
	 * 初始化HtmlUrl
	 *
	 * @memberof HtmlViewController
	 */
	public initHtmlUrl() {
		this.store.htmlUrl = fillStrData(
			this.model.htmlUrl,
			this.store.context,
			this.store.viewParams
		);
	}
}
